import RunGame from './runGame'
import Loading from './runGame/Loading'
import GameInfo from './runGame/GameInfo'


// laya初始化
Laya.init(Config.deviceWidth, Config.deviceHeight, Laya.WebGL);
// 同步代码 Laya已初始化完成

for(const key in Config.stage) { Laya.stage[key] = Config.stage[key]; }

const asset = [];
asset.push({// 单张图片
  url: [
    'res/background.png',
    'res/m_background.png',
    'res/floor.png',
    'res/item_1.png',
    'res/item_2.png',
    'res/item_3.png',
    'res/item_4.png',
    'res/bird_1.png',
    'res/bird_2.png',
    'res/bird_3.png',
    'res/bird_4.png',
    'res/effect.png',
    'res/spiritEffect.png',
    'res/en_bar.png',
    'res/hp_bar.png',
    'res/hp_bg.png',
    'res/floor.png'
  ],
  type: Laya.Loader.IMAGE
});
asset.push({// 动画帧图集
  url: 'res/player.atlas',
  type: Laya.Loader.ATLAS
});
// 加载图片
Laya.loader.load(asset, Handler.create(this, onLoaded, null, false), Handler.create(this, onLoading, null, false));

const loading = new Loading();    
const gameInfo = new GameInfo();
let runGame = null;

gameInfo.once(laya.events.Event.MOUSE_DOWN, this, onMouseDown);

Laya.stage.addChild(loading);

// 游戏介绍点击进入
function onMouseDown(){
  gameInfo.removeSelf();
  runGame.player.visible = true;
  Config.isPause = false;
}

// 加载进度
function onLoading(progress) {
  loading.progress(progress);
}

// 加载完毕
function onLoaded() {
  console.log("onLoaded");
  Laya.stage.removeChild(loading);
  Laya.stage.addChild(runGame = new RunGame());
  Laya.stage.addChild(gameInfo);
}